<?php
    require_once "utils/db.php";
	require_once "utils/util.php";
	$entityId = explode("_", $_POST['entityId']);
	$entityId = $entityId[0];
	$query = "SELECT * FROM entities WHERE `id` = '".$entityId."'";
	//alert($query);
	//vp($_POST);
	$db = new db();
		$entity = $db -> rawSelect("SELECT * FROM entities WHERE `id` = '".$entityId."'");
	$db -> close();
	vp($entity);
	$table = $entity[0]['name'];
	
	$query = "INSERT INTO ".$table." ";
	$fields =", `id`";
	$values = ", '".uuid()."'";
	foreach($_POST as $key => $val)
	{
		//echo $key."=".$val."\n\r";
		if($key != "entityId" && $key != "MAX_FILE_SIZE"){
			$fields .= ", `$key`";
			$values .= ", '".nl2br($val)."'";
		}
	}
	$fields = "( ".substr($fields, 1)." )";
	$values = nl2br("( ".substr($values, 1)." )");
	$query .= $fields." VALUES ".$values;
	//echo $query;
	//alert($query);
	//alert($values);
	//$set = substr($set,1);
	//$query .= $set." )";
	$db = new db();
		$insertedId = $db -> rawInsert($query);
	$db -> close();
	//alert($values);
	
?>